﻿using System;
using System.Collections.Generic;
using System.Text;

namespace MaximServices.Services.MottoCrawl
{
    public class CrawlResult
    {
        /// <summary>
        /// 匹配到的词条
        /// </summary>
        public List<MottoLite> Matches { get; set; }

        /// <summary>
        /// 匹配到的页面类型
        /// </summary>
        public CrawlPageType? MatchPageType { get; private set; }

        public string KeyWord { get; private set; }

        public CrawlResult(string keyword)
        {
            KeyWord = keyword;
        }

        public void NotFound()
        {
            MatchPageType = CrawlPageType.NOTFOUND;
        }

        public void FoundOne(string title, string url)
        {
            MatchPageType = CrawlPageType.ONE;

            if (Matches == null)
            {
                Matches = new List<MottoLite>();
            }

            Matches.Clear();

            Matches.Add(new MottoLite()
            {
                Title = title,
                BaiKeUrl = url
            });
        }

        public void FoundMore(List<MottoLite> matches)
        {
            MatchPageType = CrawlPageType.MUTILATE;

            Matches = matches;
        }

        public bool CanIgnoreError { get; private set; }

        public string Error { get; set; }
    }

    public class MottoLite
    {
        public string Title { get; set; }

        public string BaiKeUrl { get; set; }
    }
}
